package com.xinya.wanandroidclient.adapter

import android.text.Html
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xinya.wanandroidclient.R
import com.xinya.wanandroidclient.bean.ArticleBean
import com.xinya.wanandroidclient.utils.ColorUtils

/**
 *
 * @ClassName:      ArticleAdapter$
 * @Description:    java类作用描述
 * @Author:         xinya
 * @CreateDate:     2021/3/2$ 18:26$
 * @UpdateRemark:   更新内容
 * @Version:        1.0
 */
class ArticleAdapter(layoutResId: Int, data: MutableList<ArticleBean.Data>?) :
    BaseQuickAdapter<ArticleBean.Data, BaseViewHolder>(layoutResId, data) {

    override fun convert(holder: BaseViewHolder, item: ArticleBean.Data) {
        holder.setText(R.id.tv_article_tag, item.chapterName)
        holder.setText(R.id.tv_article_data, item.niceDate)
        holder.setText(R.id.tv_article_title, Html.fromHtml(item.title))
        holder.setText(R.id.tv_article_author, item.author)
        // 是否已经收藏
        holder.getView<ImageView>(R.id.iv_article_like).setImageResource(
            if (item.collect) R.mipmap.favorites_red else R.mipmap.favorites
        )

        holder.getView<TextView>(R.id.tv_article_title)
            .setTextColor(
                if (item.isRead) ColorUtils.parseColor(R.color.bugray_300)
                else ColorUtils.parseColor(R.color.black)
            )
        val imageView = holder.getView<ImageView>(R.id.image)
        if (TextUtils.isEmpty(item.envelopePic)) {
            imageView.visibility = View.GONE
        } else {
            Glide.with(imageView.context).load(item.envelopePic).into(imageView)
        }
    }
}